home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / Hack / MISC / HTC61.ZIP / HOWTO6_1.TXT
Encoding:
Text File  |  1996-05-18  |  22.9 KB  |  456 lines

  1.  
  2. HOW TO CRACK, by +ORC, A TUTORIAL
  3.  
  4. Lesson 6.1:  Funny tricks (1) 
  5.  
  6.  
  7. LESSON 6 (1) - Funny tricks.  Xoring, Junking, Sliding
  8. EXERCISE 01: [LARRY in search of the King]
  9.      Before the next step let's resume what you have learned in
  10. the lessons 3-5, beginning with a very simple crack exercise
  11. (again, we'll use the protection scheme of a game, for the
  12. reasons explained in lesson 1): SEARCH FOR THE KING (Version
  13. 1.1.). This old "Larry" protection sequence, is a "paper
  14. protection" primitive. It's a very widespread (and therefore easy
  15. to find) program, and one of the first programs that instead of
  16. asking meaningful passwords (which offer us the possibility to
  17. immediately track them down in memory) asked for a random number
  18. that the good buyer could find on the manual, whereby the bad
  19. cracker could not. (Here you choose -with the mouse- one number
  20. out of 5 possible for a "gadget" choosen at random). I don't need
  21. any more to teach you how to find the relevant section of code
  22. (-> see lesson 3). Once you find the protection, this is what you
  23. get:
  24.  
  25. :protection_loop
  26.  :C922 8E0614A3       MOV     ES,[A314]
  27. ...
  28.  :C952 50 0E          PUSH    AX & CS
  29.  :C954 E81BFF         CALL    C872      <- call protection scheme
  30.  :C957 5B             POP     BX twice
  31.  :C959 8B76FA         MOV     SI,[BP-06] <- prepare store_room
  32.  :C95C D1E6           SHL     SI,1       <- final prepare
  33.  :C95E 8942FC         MOV     [BP+SI-04],AX  <- store AX
  34.  :C961 837EFA00       CMP     Word Ptr [BP-06],+00  <- good_guy?
  35.  :C965 75BB           JNZ     C922           <- loop, bad guy
  36.  :C967 8E0614A3       MOV     ES,[A314]
  37.  :C96B 26F606BE3501   TEST    Byte Ptr ES:[35BE],01  <- bad_guy?
  38.  :C971 74AF           JZ C922                <- loop, bad guy
  39.  :C973 8B46FC         MOV     AX,[BP-04]...  <- go on good guy
  40.  
  41. Let's see now the protection scheme called from :C954
  42.  :C872 55             PUSH    BP
  43. ...
  44.  :C8F7 90             NOP
  45.  :C8F8 0E             PUSH    CS
  46.  :C8F9 E87234         CALL    FD6E <- call user input
  47.  :C8FC 5B             POP     BX
  48.  :C8FD 5B             POP     BX
  49.  :C8FE 8B5E06         MOV     BX,[BP+06]
  50.  :C901 D1E3           SHL     BX,1
  51.  :C903 39872266       CMP     [BX+6622],AX  <- right answer?
  52.  :C907 7505           JNZ     C90E      <- no, beggar_off
  53.  :C909 B80100         MOV     AX,0001   <- yes, AX=1
  54.  :C90C EB02           JMP     C910
  55.  :C90E 2BC0           SUB     AX,AX     <- beggar_off with AX=0
  56.  :C910 8BE5           MOV     SP,BP
  57.  :C912 5D             POP     BP
  58.  :C913 CB             RETF              <- back to main
  59.  
  60. Here follow 5 questions, please answer all of them:
  61. 1)   Where in memory (in which locations) are stored the "right"
  62.      passnumbers? Where in memory is the SEGMENT of this
  63.      locations stored? How does the scheme get the OFFSET?
  64. 2)   Would setting NOPs instructions at :C965 and :C971 crack?
  65.      Would it be a good idea?
  66. 3)   Would changing :C907 to JZ crack? Would it be a good idea?
  67. 4)   Would changing :C907 to JNZ C909 crack? Would it be a good
  68.      idea?
  69. 5)   Write down (and try) at least 7 OTHER different patches to
  70.      crack this scheme in spades (without using any NOP!).
  71. Uff! By now you should be able to do the above 5 exercises in
  72. less than 15 minutes WITHOUT USING THE DEBUGGER! Just look at the
  73. data above and find the right answers feeling them... (you 'll
  74. now which one are the right one checking with your debugger...
  75. score as many points as you like for each correct answer and sip
  76. a good Martini-Wodka... do you know that the sequence should
  77. ALWAYS be 1) Ice cubes 2) Martini Dry 3) Wodka Moskovskaja 4)
  78. olive 5) lemon 6) Schweppes Indian tonic?
  79.  
  80. Let's now come to the subject of this lesson:
  81. -----> [Xoring] (Simple encryption methods)
  82.      One easy way to encrypt data is the XOR method. XOR is a bit
  83. manipulation instruction that can be used in order to cipher and
  84. decipher data with the same key:
  85.  Byte to encrypt                   key            result
  86.      FF                  XOR       A1               5E
  87.      5E                  XOR       A1               FF
  88. As you can see XOR offers a very easy way to encrypt or to
  89. decrypt data, for instance using the following routine:
  90.  encrypt_decrypt:
  91.      mov  bx, offset_where_encryption/decryption_starts
  92.  xor_loop:
  93.      mov  ah, [bx]            <-   get current byte
  94.      xor  ah, encrypt_value   <-   engage/disengage xor
  95.      mov [bx], ah             <-   back where you got it
  96.      inc  bx                  <-   ahead one byte
  97.      cmp  bx, offset_start_+_size  <- are we done?
  98.      jle  xor_loop            <-   no, then next cycle
  99.      ret                      <-   back where we came from
  100.  
  101. The encrypt_value can be always the same (fixed) or chosen at
  102. random, for instance using INT_21, service 2Ch (get current time)
  103. and choosing as encrypt_value the value reported in DL (but
  104. remembering to discard the eventual value 0, coz otherwise it
  105. would not xor anything at all!)
  106.  random_value:
  107.      mov  ah,2Ch
  108.      int  21h
  109.      cmp  dl,0
  110.      je   random_value
  111.      mov  encrypt_value,dl
  112.      The problem with XORing (and with many other encryption
  113. methods), is that the part of the code that calls the encryption
  114. routine cannot be itself encrypted. You'll somewhere have, "in
  115. clear" the encryption key.
  116.  
  117.      The protectionist do at times their best to hide the
  118. decrypting routine, here are some common methods:
  119.  
  120. -----> JUNK FILLING, SLIDING KEYS AND MUTATING DECRYPTORS
  121.   These are the more common protection method for the small
  122. decryption part of the program code. This methods, originally
  123. devised to fool signature virus scanners, have been pinched from
  124. the polymorphic virus engines of our fellows viriwriters, and are
  125. still in use for many simple decryption protection schemes. For
  126. parts of the following many thanks go to the [Black Baron], it's
  127. a real pity that so many potential good crackers dedicate so much
  128. time to useless (and pretty repetitive) virus writing instead of
  129. helping in our work. This said, virus studying is VERY important
  130. for crackers coz the code of the viri is
  131. *    ULTRAPROTECTED
  132. *    TIGHT AND EFFECTIVE
  133. *    CLOAKED AND CONCEALED.
  134.  
  135. Let's show as example of the abovementioned protection tactics
  136. the following ultra-simple decryptor:
  137.           MOV      SI,jumbled_data     ;Point to the jumbled data
  138.           MOV      CX,10               ;Ten bytes to decrypt
  139. mn_loop:  XOR      BYTE PTR [SI],44    ;XOR (un_scramble!) a byte
  140.           INC      SI                  ;Next byte
  141.           LOOP     mn_loop             ;Loop the 9 other bytes
  142.  
  143. This small program will XOR the ten bytes at the location pointed
  144. to by SI with the value 44.  Providing the ten bytes were XORed
  145. with 44 prior to running this decryptor the ten bytes will be
  146. restored to their original state.
  147. In this very simple case the "key" is the value 44. But there are
  148. several tricks involving keys, the simplest one being the use of
  149. a "sliding" key: a key that will be increased, or decreased, or
  150. multiplied, or bit-shifted, or whatever, at every pass of the
  151. loop.
  152.  
  153. A possible protection can also create a true "Polymorph"
  154. decryptor, a whole decryptor ROUTINE that looks completely
  155. different on each generation. The trick is to pepper totally
  156. random amounts of totally random instructions, including JUMPS
  157. and CALLS, that DO NOT AFFECT the registers that are used for the
  158. decryption. Also this kind of protection oft uses a different
  159. main decryptor (possibly from a selection of pre-coded ones) and
  160. oft alters on each generation also all the registers that the
  161. decryptor uses, invariably making sure that the JUNK code that
  162. it generates doesn't destroy any of the registers used by the
  163. real decryptor!  So, with these rules in mind, here is our simple
  164. decryptor again:
  165.  
  166.          MOV      DX,10              ;Real part of the decryptor!
  167.          MOV      SI,1234            ;junk
  168.          AND      AX,[SI+1234]       ;junk
  169.          CLD                         ;junk
  170.          MOV      DI,jumbled_data    ;Real part of the decryptor!
  171.          TEST     [SI+1234],BL       ;junk
  172.          OR       AL,CL              ;junk
  173. mn_loop: ADD      SI,SI              ;junk instr, but real loop!
  174.          XOR      AX,1234            ;junk
  175.          XOR      BYTE PTR [DI],44   ;Real part of the decryptor!
  176.          SUB      SI,123             ;junk
  177.          INC      DI                 ;Real part of the decryptor!
  178.          TEST     DX,1234            ;junk
  179.          AND      AL,[BP+1234]       ;junk
  180.          DEC      DX                 ;Real part of the decryptor!
  181.          NOP                         ;junk
  182.          XOR      AX,DX              ;junk
  183.          SBB      AX,[SI+1234]       ;junk
  184.          AND      DX,DX              ;Real part of the decryptor!
  185.          JNZ      mn_loop            ;Real part of the decryptor!
  186.  
  187. As you should be able to see, quite a mess! But still executable
  188. code. It is essential that any junk code generated by the
  189. Polymorph protection is executable, as it is going to be peppered
  190. throughout the decryptor. Note, in this example, that some of the
  191. junk instructions use registers that are actually used in the
  192. decryptor! This is fine, providing the values in these
  193. registers aren't destroyed. Also note, that now we have random
  194. registers and random instructions on each generation. So, a
  195. Polymorph protection Engine can be summed up into three major
  196. parts:
  197.   1 .. The random number generator.
  198.   2 .. The junk code generator.
  199.   3 .. The decryptor generator.
  200. There are other discrete parts but these three are the ones where
  201. most of the work goes on!
  202.  
  203. How does it all work?  Well a good protection would
  204. *    choose a random selection of registers to use for the
  205. decryptor and leave the remaining registers as "junk" registers
  206. for the junk code generator.
  207. *    choose one of the compressed pre-coded decryptors.
  208. *    go into a loop generating the real decryptor, peppered with
  209. junk code.
  210. From the protectionist's point of view, the advantages of this
  211. kind of method are mainly:
  212. *    the casual cracker will have to sweat to find the decryptor.
  213. *    the casual cracker will not be able to prepare a "patch" for
  214. the lamers, unless he locates and patches the generators, (that
  215. may be compressed) coz otherwise the decryptor will vary every
  216. time.
  217.  
  218. To defeat this kind of protection you need a little "zen" feeling
  219. and a moderate knowledge of assembler language... some of the
  220. junk instructions "feel" quite singular when you look at them
  221. (->see lesson B). Besides, you (now) know what may be going on
  222. and memory breakpoints will immediately trigger on decryption...
  223. the road is open and the rest is easy (->see lessons 3-5).
  224.  
  225. -----> Starting point number magic
  226. For example, say the encrypted code started at address 10h, the
  227. following could be used to index this address:
  228.  MOV   SI,10h         ;Start address
  229.  MOV   AL,[SI]        ;Index from initial address
  230. But sometimes you'll instead find something like the following,
  231. again based on the encrypted code starting at address 10h:
  232.  
  233.  MOV   DI,0BFAAh      ;Indirect start address
  234.  MOV   AL,[DI+4066h)  ;4066h + 0BFAAh = 10010h (and FFFF = 10h)!!
  235. The possible combinations are obviously infinite.
  236.  
  237.  
  238. [BIG KEYS] (Complicated encryption methods)
  239.      Prime number factoring is the encryption used to protect
  240. sensible data and very expensive applications. Obviously for few
  241. digit keys the decoding is much easier than for, say, 129 or 250
  242. digit keys. Nevertheless you can crack those huge encryption too,
  243. using distributed processing of quadratic sieve equations (which
  244. is far superior for cracking purpose to the sequential processing
  245. methods) in order to break the key into prime numbers. To teach
  246. you how to do this sort of "high" cracking is a little outside
  247. the scope of my tutorial: you'll have to write a specific short
  248. dedicated program, linking together more or less half a thousand
  249. PC for a couple of hours, for a 250 bit key, this kind of things
  250. have been done quite often on Internet, were you can also find
  251. many sites that do untangle the mysteries (and vagaries) of such
  252. techniques.
  253.   As References I would advocate the works of Lai Xueejia, those
  254. swiss guys can crack *everything*. Begin with the following:
  255. Xuejia Lai, James Massey, Sean Murphy, "Markov Ciphers and
  256.      Differential Cryptanalysis", Advances in Cryptology,
  257.      Eurocrypt 1991.
  258. Xuejia Lai, "On the Design and Security of Block Ciphers",
  259.      Institute for Signal and Information Processing,
  260.      ETH-Zentrum, Zurich, Switzerland, 1992
  261. Factoring and primality testing is obviously very important for
  262. this kind of crack. The most comprehensive work I know of is:
  263. (300 pages with lengthy bibliography!)
  264.     W. Bosma & M. van der Hulst
  265.     Primality Testing with Cyclotomy
  266.     Thesis, University of Amsterdam Press.
  267. A very good old book you can incorporate in your probes to build
  268. very effective crack programs (not only for BBS accesses :=) is
  269. *the* "pomerance" catalog:
  270. Pomerance, Selfridge, & Wagstaff Jr.
  271.     The pseudoprimes to 25*10^9
  272.     Math. Comp. Vol 35 1980 pp. 1003-1026
  273.  
  274. Anyway... make a good search with Lykos, and visit the relevant
  275. sites... if encryption really interests you, you'll be back in
  276. two or three (or thirty) years and you'll resume cracking with
  277. deeper erudite knowledge.
  278. [PATENTED PROTECTION SYSTEMS]
  279.   The study of the patented enciphering methods is also *quite*
  280. interesting for our aims :=) Here are some interesting patents,
  281. if you want to walk these paths get the complete texts:
  282.      [BEST]    USPat 4168396 to Best discloses a microprocessor
  283. for executing enciphered programs. Computer programs which have
  284. been enciphered during manufacture to deter the execution of the
  285. programs in unauthorized computers, must be decrypted before
  286. execution. The disclosed microprocessor deciphers and executes
  287. an enciphered program one instruction at a time, instead of on
  288. a continuous basis, through a combination of substitutions,
  289. transpositions, and exclusive OR additions, in which the address
  290. of each instruction is combined with the instruction. Each unit
  291. may use a unique set of substitutions so that a program which can
  292. be executed on one microprocessor cannot be run on any other
  293. microprocessor. Further, Best cannot accommodate a mixture of
  294. encrypted and plain text programs.
  295.      [JOHNSTONE]    USPat 4120030 to Johnstone describes a
  296. computer in which the data portion of instructions are scrambled
  297. and in which the data is of necessity stored in a separate
  298. memory. There is no disclosure of operating with instructions
  299. which are completely encrypted with both the operation code and
  300. the data address portion being unreadable without a corresponding
  301. key kernel.
  302.      [TWINPROGS]    USPat 4183085 describes a technique for
  303. protecting software by providing two separate program storages.
  304. The first program storage is a secure storage and the second
  305. program storage is a free storage. Security logic is provided to
  306. check whether an output instruction has originated in the secure
  307. store and to prevent operation of an output unit which receives
  308. output instructions from the free storage. This makes it
  309. difficult to produce information by loading a program into free
  310. storage.
  311.      [AUTHENTICATOR]     USPat 3996449 entitled "Operating System
  312. Authenticator," discloses a technique for authenticating the
  313. validity of a plain text program read into a computer, by
  314. exclusive OR'ing the plain text of the program with a key to
  315. generate a code word which must be a standard recognizable code
  316. word which is successfully compared with a standard corresponding
  317. code word stored in the computer. If there is a successful
  318. compare, then the plain text program is considered to be
  319. authenticated and is allowed to run, otherwise the program
  320. is not allowed to run.
  321.  
  322. ELEMENTS OF [PGP] CRACKING
  323. In order to try to crack PGP, you need to understand how these
  324. public/private keys systems work. Cracking PGP seems extremely
  325. difficult, though... I have a special dedicated "attack" computer
  326. that runs 24 hours on 24 only to this aim and yet have only begun
  327. to see the light at the famous other end of the tunnel. It's
  328. hard, but good crackers never resign! We'll see... I publish here
  329. the following only in the hope that somebody else will one day
  330. be able to help...
  331. In the public key cryptosystems, like PGP, each user has an
  332. associated encryption key E=(e,n) and decryption key D=(d,n),
  333. wherein the encryption keys for all users are available in a
  334. public file, while the decryption keys for the users are only
  335. known to the respective users. In order to maintain a high level
  336. of security a user's decoding key is not determinable in a
  337. practical manner from that user's encoding (public) key. Normally
  338. in such systems, since
  339.      e.multidot.d.ident.1 (mod(1 cm((p-1),(q-1)))),
  340. (where "1 cm((p-1),(q-1))" is the least common multiple of the
  341. numbers p-1 and q-1)
  342.  
  343. d can be determined from e provided p and q are also known.
  344. Accordingly, the security of the system is dependent upon the
  345. ability to determine p and q which are the prime factors of n.
  346. By selecting p and q to be large primes, the resultant composite
  347. number n is also large, and correspondingly difficult to factor.
  348. For example, using known computer-implemented factorization
  349. methods, on the order of 10.sup.9 years is required to factor a
  350. 200 digit long number. Thus, as a practical matter, although a
  351. user's encryption key E=(e,n) is public, the prime factors p and
  352. q of n are effectively hidden from anyone due to the enormous
  353. difficulty in factoring n. These aspects are described more fully
  354. in the abundant publications on digital signatures and Public-Key
  355. Cryptosystems. Most public/private systems relies on a message-
  356. digest algorithm.
  357.   A message-digest algorithm maps a message of arbitrary length
  358. to a "digest" of fixed length, and has three properties:
  359. Computing the digest is easy, finding a message with a given
  360. digest "inversion" is hard, and finding two messages with the
  361. same digest "collision" is also hard. Message-digest algorithms
  362. have many applications, not only digital signatures and message
  363. authentication. RSA Data Security's MD5 message-digest algorithm,
  364. developed by Ron Rivest, maps a message to a 128-bit message
  365. digest. Computing the digest of a one-megabyte message takes as
  366. little as a second.  While no message-digest algorithm can yet
  367. be secure, MD5 is believed to be at least as good as any other
  368. that maps to a 128-bit digest.
  369.   As a final gift, I'll tell you that PGP relies on MD5 for a
  370. secure one-way hash function. For PGP this is troublesome, to say
  371. the least, coz an approximate relation exists between any four
  372. consecutive additive constants. This means that one of the design
  373. principles behind MD4 (and MD5), namely to design a collision
  374. resistant function, is not satisfied. You can construct two
  375. chaining variables (that only differ in the most significant bit
  376. of every word) and a single message block that yield the same
  377. hashcode. The attack takes a few minutes on a PC. From here you
  378. should start, as I did.
  379.  
  380. [DOS 4GW] cracking - This is only a very provisory part of this
  381. tutorial. DOS 4GW cracking will be much better described as soon
  382. as [Lost soul] sends his stuff, if he ever does. For (parts of)
  383. the following I thank [The Interrupt].
  384.      Most applications of every OS, and also of DOS 4GW, are
  385. written in C language, coz as you'll have already learned or,
  386. either, you'll learn, only C allows you to get the "guts" of a
  387. program, almost approaching the effectiveness of assembler
  388. language.
  389.      C is therefore the LANGUAGE OF CHOICE for crackers, when you
  390. prepare your tools and do not directly use assembler routines.
  391. Besides... you'll be able to find VERY GOOD books about C for
  392. next to nothing in the second hand bookshops. All the lusers are
  393. throwing money away in spades buying huge, coloured and
  394. absolutely useless books on unproductive "bloated" languages like
  395. Visual basic, C++ and Delphy. Good C new books are now rare
  396. (books on assembler language have always been) and can be found
  397. almost exclusively on the second hand market. Find them, buy
  398. them, read them, use them for your/our aims. You can find a lot
  399. of C tutorials and of C material on the Web, by all means DO IT!
  400. Be a conscientious cracker... learn C! It's cheap, lean, mean and
  401. very productive (and creative) :=)
  402.      Back to the point: most stuff is written in C and therefore
  403. you need to find the "main" sub-routine inside the asm. With
  404. DOS/4GW programs, search the exe file for "90 90 90 90", almost
  405. always it'll be at the start of the compiled code. Now search for
  406. an INT_21 executed with 4C in AH, the exec to dos code (if you
  407. cannot "BPINT 21 AH=4C" with your tool, then search for the
  408. sequence "b4 4c cd 21". This is the equivalent to [mov AH,4C &
  409. int 21]: it's the most direct call, but as you'll have already
  410. learned, there are half a dozen ways to put 4C in AX, try them
  411. all in the order of their frequency).
  412.      A few bytes above the INT_21 service 4C, you'll find the
  413. call to the "main" subroutine: "E8 xx xx". Now place a "CC" byte
  414. a few bytes above the call in the exe and run the exe under a
  415. debugger. When the computer tries to execute the instruction
  416. you'll be throw back in the debugger coz the "CC" byte acts as
  417. INT_01 instruction. Then proceed as usual.
  418.  
  419. [THE "STEGONATED" PASSWORD HIDEOUT]
  420.   A last, very nice trick should be explained to every wannabe
  421. cracker, coz it would be embarrassing to search for passwords or
  422. protection routines that (apparently) are not there. They may be
  423. hidden INSIDE a picture (or a *.waw file for that matter). This
  424. is steganography, a method of disguising messages within other
  425. media.
  426.   Depending on how many shades of grey or hues of colour you want
  427. to have, a pixel can be expressed using 8. 16, 32 or even more
  428. bits. If the least significant bit is changed. the shade of the
  429. pixel is altered only one-256th, one-65,OOOth or even less. No
  430. human eye could tell the difference.
  431.   What the protectionist does, is hijack the least significant
  432. bit in each pixel of a picture. It uses that bit to store one bit
  433. of a protection, or of a password (or of a file, or of a secret
  434. message). Because digitized pictures have lots of pixels, it's
  435. possible to store lots of data in a single picture. A simple
  436. algorithm will transfer them to the relevant parts of the program
  437. when it needs be, and there we'll intercept them. You'll need to
  438. learn very well the zen-cracking techniques to smell this kind
  439. of stuff though (-> see lesson B).
  440.  
  441. Well, that's it for this lesson, reader. Not all lessons of my
  442. tutorial are on the Web.
  443.  
  444.      You 'll obtain the OTHER missing lessons IF AND ONLY IF you
  445. mail me back (via anon.penet.fi) with some tricks of the trade
  446. I may not know that YOU discovered. Mostly I'll actually know
  447. them already, but if they are really new you'll be given full
  448. credit, and even if they are not, should I judge that you
  449. "rediscovered" them with your work, or that you actually did good
  450. work on them, I'll send you the remaining lessons nevertheless.
  451. Your suggestions and critics on the whole crap I wrote are also
  452. welcomed.
  453.  
  454. an526164@anon.penet.fi (+ORC) 
  455.  
  456.